//
//  YDContactHeaderView.m
//  IngCard
//
//  Created by kf on 2017/10/16.
//  Copyright © 2017年 IngDan. All rights reserved.
//

#import "YDContactHeaderView.h"

@interface  YDContactHeaderView()
@property(nonatomic, strong) UIImageView *backgroundImageView;
@property(nonatomic, strong) UIButton *backButton;
@property(nonatomic, strong) UILabel *titleLabel;
@property(nonatomic, strong) UIButton *moreButton;

@property(nonatomic, strong) UILabel *nameLabel;
@property(nonatomic, strong) UILabel *occupationLabel;//职位
@property(nonatomic, strong) UILabel *companyLabel;

@property(nonatomic, strong) UIButton *remarkButton1;
@property(nonatomic, strong) UIButton *remarkButton2;
@property(nonatomic, strong) UIButton *remarkButton3;
@property(nonatomic, strong) UIButton *plusButton;

@property(nonatomic, strong) UIButton *phoneButton;
@property(nonatomic, strong) UIButton *msmButton;
@property(nonatomic, strong) UIButton *emailButton;
@property(nonatomic, strong) UIButton *chatButton;


@end

@implementation YDContactHeaderView
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self initSubviews];
    }
    return self;
}

-(void) initSubviews
{
//    self.backgroundColor = UIColorRed;
    
    [self makeConstraints:^(MASConstraintMaker *make) {
        make.width.equalTo(SCREEN_WIDTH);
        make.height.equalTo(249 + 59 + 6);
    }];
    
    [self addSubview:self.backgroundImageView];
    [self.backgroundImageView makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(0);
        make.top.equalTo(self);//self.contentView).offset(0);
        make.height.equalTo(249);
    }];
    
    [self addSubview:self.backButton];
    [self.backButton makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(7.5);
        make.top.equalTo(44);
    }];
    
    [self addSubview:self.titleLabel];
    [self.titleLabel makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self);
        make.centerY.equalTo(self.backButton);
    }];
    
    [self addSubview:self.moreButton];
    [self.moreButton makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.backButton);
        make.right.equalTo(self).offset(-26);
    }];
    
    [self addSubview:self.nameLabel];
    [self.nameLabel makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(18);
        make.top.equalTo(73);
        make.right.lessThanOrEqualTo(self).offset(-18);
    }];
    
    [self addSubview:self.occupationLabel];
    [self.occupationLabel makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.nameLabel);
        make.top.equalTo(self.nameLabel.mas_bottom).offset(5);
        make.right.lessThanOrEqualTo(self).offset(-18);
    }];
    
    [self addSubview:self.companyLabel];
    [self.companyLabel makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.nameLabel);
        make.top.equalTo(self.occupationLabel.mas_bottom).offset(5);
        make.right.lessThanOrEqualTo(self).offset(-18);
    }];
    
    [self addSubview:self.remarkButton1];
    [self.remarkButton1 makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(20);
        make.bottom.equalTo(self.backgroundImageView).offset(-16);
    }];
    
    [self addSubview:self.remarkButton2];
    [self.remarkButton2 makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.remarkButton1.mas_right).offset(10);
        make.centerY.equalTo(self.remarkButton1);
    }];
    
    [self addSubview:self.remarkButton3];
    [self.remarkButton3 makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.remarkButton2.mas_right).offset(10);
        make.centerY.equalTo(self.remarkButton1);
    }];
    
    [self addSubview:self.plusButton];
    [self.plusButton makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.remarkButton3.mas_right).offset(10);
        make.centerY.equalTo(self.remarkButton1);
    }];
    
    [self addSubview:self.phoneButton];
    [self.phoneButton makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(40);
        make.top.equalTo(self.backgroundImageView.mas_bottom).offset(26);
    }];
    
    [self addSubview:self.msmButton];
    [self.msmButton makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.phoneButton);
        make.left.equalTo(self.phoneButton.mas_right).offset(66);
    }];
    
    [self addSubview:self.emailButton];
    [self.emailButton makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.phoneButton);
        make.left.equalTo(self.msmButton.mas_right).offset(66);
    }];
    
    [self addSubview:self.chatButton];
    [self.chatButton makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.phoneButton);
        make.left.equalTo(self.emailButton.mas_right).offset(66);
    }];
}

#pragma mark - private
- (void)backButtonAction:(UIButton *)btn
{
    BlockGoGo(self.back);
}

- (void)moreButtonAction:(UIButton *)btn
{
    
}

- (void)remarkButtonAction:(UIButton *)btn
{
    
}

- (void)plusButtonAction:(UIButton *)btn
{
    
}

-(void)phoneButtonAction:(UIButton *) btn
{
    NSString *telephoneNumber=@"18500522131";
    NSMutableString * str=[[NSMutableString alloc] initWithFormat:@"tel:%@",telephoneNumber];
    UIApplication *application = [UIApplication sharedApplication];
    NSURL *URL = [NSURL URLWithString:str];
    [application openURL:URL options:@{} completionHandler:^(BOOL success) {
        //OpenSuccess=选择 呼叫 为 1  选择 取消 为0
        NSLog(@"OpenSuccess=%d",success);
        
    }];
}

-(void)msmButtonAction:(UIButton *) btn
{
    [[UIApplication sharedApplication]openURL:[NSURL URLWithString:@"sms://1850052231"]];
}
-(void)emailButtonAction:(UIButton *) btn
{
    NSMutableString *mailUrl = [[NSMutableString alloc] init];
    //添加收件人,如有多个收件人，可以使用componentsJoinedByString方法连接，连接符为","
    NSString *recipients = @"sparkle_ds@163.com";
    [mailUrl appendFormat:@"mailto:%@?", recipients];
    //添加抄送人
    NSString *ccRecipients = @"1622849369@qq.com";
    [mailUrl appendFormat:@"&cc=%@", ccRecipients];
    //添加密送人
    NSString *bccRecipients = @"15690725786@163.com";
    [mailUrl appendFormat:@"&bcc=%@", bccRecipients];
    //添加邮件主题
    [mailUrl appendFormat:@"&subject=%@",@"设置邮件主题"];
    //添加邮件内容
    [mailUrl appendString:@"&body=<b>Hello</b> World!"];
    //跳转到系统邮件App发送邮件
    NSString *emailPath = [mailUrl stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLFragmentAllowedCharacterSet]];
    [[UIApplication sharedApplication]openURL:[NSURL URLWithString:emailPath] options:@{} completionHandler:nil];
}
#pragma mark - lazy load

-(UIImageView *) backgroundImageView
{
    if (!_backgroundImageView)
    {
        _backgroundImageView = [UIImageView new];
        UIImage *image = UIImageMake(@"contact_detail_head");
        CGFloat width =  image.size.width;
        CGFloat height = image.size.height;
        
        _backgroundImageView.image = [image qmui_imageWithScaleToSize:CGSizeMake(SCREEN_WIDTH, (SCREEN_WIDTH * height) /width) contentMode:UIViewContentModeScaleToFill];
        _backgroundImageView.contentMode = UIViewContentModeCenter;
        
        [_backgroundImageView sizeToFit];
    }
    return _backgroundImageView;
}

-(UIButton *) backButton
{
    if (!_backButton)
    {
        _backButton = [[UIButton alloc] init];
        _backButton.frame = CGRectMake(0, 0, 15, 17);
        [_backButton setBackgroundImage:UIImageMake(@"myCard_search") forState:UIControlStateNormal];
        _backButton.layer.masksToBounds = YES;
        [_backButton addTarget:self
                          action:@selector(backButtonAction:)
                forControlEvents:UIControlEventTouchUpInside];
    }
    return _backButton;
}

- (UILabel *) titleLabel
{
    if (!_titleLabel)
    {
        _titleLabel = [[UILabel alloc] init];
        _titleLabel.text = @"联系人详情";
        _titleLabel.textAlignment = NSTextAlignmentCenter;
        _titleLabel.font = UIFontLightMake(20);
        _titleLabel.textColor = UIColorWhite;
        [_titleLabel sizeToFit];
    }
    return _titleLabel;
}

-(UIButton *)moreButton
{
    if (!_moreButton)
    {
        _moreButton = [[UIButton alloc] init];
        _moreButton.frame = CGRectMake(0, 0, 15, 15);
        [_moreButton setBackgroundImage:UIImageMake(@"userGuideButtonImage") forState:UIControlStateNormal];
        _moreButton.layer.masksToBounds = YES;
        [_moreButton addTarget:self
                        action:@selector(moreButtonAction:)
              forControlEvents:UIControlEventTouchUpInside];
    }
    return _moreButton;
}

-(UILabel *) nameLabel
{
    if (!_nameLabel)
    {
        _nameLabel = [[UILabel alloc] init];
        _nameLabel.text = @"John Defterios";
        _nameLabel.textAlignment = NSTextAlignmentLeft;
        _nameLabel.font = UIFontLightMake(23);
        _nameLabel.textColor = UIColorMake(255, 255, 255);
        [_nameLabel sizeToFit];
    }
    return _nameLabel;
}

-(UILabel *) occupationLabel
{
    if (!_occupationLabel)
    {
        _occupationLabel = [[UILabel alloc] init];
        _occupationLabel.text = @"Editor";
        _occupationLabel.textAlignment = NSTextAlignmentLeft;
        _occupationLabel.font = UIMediumFontMake(17);
        _occupationLabel.textColor = UIColorMake(255, 255, 255);
        [_occupationLabel sizeToFit];
    }
    return _occupationLabel;
}

-(UILabel *) companyLabel
{
    if (!_companyLabel)
    {
        _companyLabel = [[UILabel alloc] init];
        _companyLabel.text = @"Cable News Network";
        _companyLabel.textAlignment = NSTextAlignmentLeft;
        _companyLabel.font = UIMediumFontMake(17);
        _companyLabel.textColor = UIColorMake(255, 255, 255);
        [_companyLabel sizeToFit];
    }
    return _companyLabel;
}

-(UIButton *)remarkButton1
{
    if (!_remarkButton1)
    {
        _remarkButton1 = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 150, 26)];
        _remarkButton1.layer.cornerRadius = 16;
        _remarkButton1.layer.borderColor = UIColorMake(255, 255, 255).CGColor;
        _remarkButton1.layer.borderWidth = 1;
        _remarkButton1.layer.masksToBounds = YES;
        
        _remarkButton1.contentEdgeInsets = UIEdgeInsetsMake(6, 16, 6, 16);
        
        [_remarkButton1 setTitleColor:UIColorMake(255, 255, 255) forState:UIControlStateNormal];
        [_remarkButton1 setTitle:@"Customer" forState:UIControlStateNormal];
        [_remarkButton1 addTarget:self
                        action:@selector(remarkButtonAction:)
              forControlEvents:UIControlEventTouchUpInside];
        [_remarkButton1 sizeToFit];
    }
    return _remarkButton1;
}

-(UIButton *)remarkButton2
{
    if (!_remarkButton2)
    {
        _remarkButton2 = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 150, 26)];
        _remarkButton2.layer.cornerRadius = 16;
        _remarkButton2.layer.borderColor = UIColorMake(255, 255, 255).CGColor;
        
        _remarkButton2.contentEdgeInsets = UIEdgeInsetsMake(6, 16, 6, 16);
        _remarkButton2.layer.borderWidth = 1;
        [_remarkButton2 setTitleColor:UIColorMake(255, 255, 255) forState:UIControlStateNormal];
        [_remarkButton2 setTitle:@"Maybe-Partner" forState:UIControlStateNormal];
        _remarkButton2.layer.masksToBounds = YES;
        [_remarkButton2 addTarget:self
                           action:@selector(remarkButtonAction:)
                 forControlEvents:UIControlEventTouchUpInside];
        
        [_remarkButton2 sizeToFit];
    }
    return _remarkButton2;
}

-(UIButton *)remarkButton3
{
    if (!_remarkButton3)
    {
        _remarkButton3 = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 150, 26)];
        _remarkButton3.layer.cornerRadius = 16;
        _remarkButton3.layer.borderColor = UIColorMake(255, 255, 255).CGColor;
        
        _remarkButton3.contentEdgeInsets = UIEdgeInsetsMake(6, 16,6, 16);
        _remarkButton3.layer.borderWidth = 1;
        [_remarkButton3 setTitleColor:UIColorMake(255, 255, 255) forState:UIControlStateNormal];
        [_remarkButton3 setTitle:@"Rich" forState:UIControlStateNormal];
        _remarkButton3.layer.masksToBounds = YES;
        [_remarkButton3 addTarget:self
                           action:@selector(remarkButtonAction:)
                 forControlEvents:UIControlEventTouchUpInside];
        [_remarkButton3 sizeToFit];
    }
    return _remarkButton3;
}



-(UIButton *)plusButton
{
    if (!_plusButton)
    {
        _plusButton = [[UIButton alloc] init];
        _plusButton.frame = CGRectMake(0, 0, 15, 15);
        [_plusButton setBackgroundImage:UIImageMake(@"myCard_plus") forState:UIControlStateNormal];
        _plusButton.layer.masksToBounds = YES;
        [_plusButton addTarget:self
                        action:@selector(plusButtonAction:)
              forControlEvents:UIControlEventTouchUpInside];
    }
    return _plusButton;
}

-(UIButton *)phoneButton
{
    if (!_phoneButton)
    {
        _phoneButton = [[UIButton alloc] init];
        _phoneButton.frame = CGRectMake(0, 0, 24, 25);
        _phoneButton.layer.masksToBounds = YES;
        [_phoneButton setImage:UIImageMake(@"contact_phone") forState:UIControlStateNormal];
        [_phoneButton addTarget:self action:@selector(phoneButtonAction:) forControlEvents:UIControlEventTouchUpInside];
        [_phoneButton sizeToFit];
    }
    return _phoneButton;
}

-(UIButton *)msmButton
{
    if (!_msmButton)
    {
        _msmButton = [UIButton new];
        _msmButton.frame = CGRectMake(0, 0, 24, 25);
        _msmButton.layer.masksToBounds = YES;
        [_msmButton setImage:UIImageMake(@"contact_msm") forState:UIControlStateNormal];
        [_msmButton addTarget:self action:@selector(msmButtonAction:) forControlEvents:UIControlEventTouchUpInside];
        [_msmButton sizeToFit];
    }
    return _msmButton;
}

-(UIButton *)emailButton
{
    if (!_emailButton)
    {
        _emailButton = [UIButton new];
        _emailButton.frame = CGRectMake(0, 0, 24, 25);
        _emailButton.layer.masksToBounds = YES;
        [_emailButton setImage:UIImageMake(@"contact_email") forState:UIControlStateNormal];
        [_emailButton addTarget:self action:@selector(emailButtonAction:) forControlEvents:UIControlEventTouchUpInside];
//        [_emailButton sizeToFit];
    }
    return _emailButton;
}

-(UIButton *)chatButton
{
    if (!_chatButton)
    {
        _chatButton = [UIButton new];
        _chatButton.frame = CGRectMake(0, 0, 24, 25);
        _chatButton.layer.masksToBounds = YES;
        [_chatButton setImage:UIImageMake(@"contact_chat") forState:UIControlStateNormal];
//        [_chatButton sizeToFit];
    }
    return _chatButton;
}

@end
